if !exists('s:loaded')
    let s:loaded=1
else
    " finish 
endif

let g:libpath=[ "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages" ]

let s:python_path= expand('<sfile>:p:h').'/python'
function python#init_env()
    autocmd BufReadPost *.cmd_history setlocal filetype=cmd_history
    autocmd BufReadPost *.cmd_result setlocal filetype=cmd_result
    execute ':py3 sys.path.insert(0,"'. s:python_path .'")'
    execute ':py3 sys.path.extend(' .string(g:libpath) .')'
    execute 'py3 print(sys.path[0],sys.path[-1])'
    execute 'py3f '.s:python_path .'/vim_use.py'
    execute 'py3f '.s:python_path .'/vim_mapping.py'
endfunction
function python#input_and_execute_os_cmd()
    let l:cmd=input('input_os_cmd:')
    call python#execute_os_cmd(l:cmd)
endfunction
function python#execute_os_cmd(cmd)
   execute ':py3 execute_os_cmd("' .a:cmd .'")' 
endfunction
function python#run_server(channel,msg)
    echo 'server'.a:msg
endfunction
function python#start_server()
    if exists('g:python#server') &&job_status(g:python#server)=='run'
        return
    endif
    let g:python#server= job_start(['python3',s:python_path.'/vim_server.py'], {'callback': 'python#run_server','err_io':'out',"out_io": "file","out_name":s:python_path.'/server.log'})
endfunction

function python#close_server()
    if exists('g:python#server') &&job_status(g:python#server)=='run'
        echo 'close'
        call  job_stop(g:python#server)
    endif
endfunction
function python#show_os_cmd_history()
    execute ':py3 show_os_cmd_history()'
endfunction

